package pearson.automation.assets;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import framework.elements.ElementList;

public class AssetList {
    private String listXPath;
    private String elementXPathTemplate;
    private ElementList list;
    private List<WebElement> elements;
    
    public AssetList(String listXPath, String elementTemplate) {
        this.listXPath = listXPath;
        this.elementXPathTemplate = elementTemplate;
        list = new ElementList(By.xpath(listXPath), "Asset List");
    }
    
    public int getListSize() {
        if (list.isPresent()) {
            elements = list.getElement().findElementsByXPath(listXPath + elementXPathTemplate);
            return elements.size();
        } else {
            return 0;
        }
    }
    
    public AssetWithRollOver getAsset(String title) {
        String elementXPath = String.format("%s%s[contains(.,'%s')]", listXPath, elementXPathTemplate, title);
        return new AssetWithRollOver(elementXPath, true);
    }
    
    public AssetWithRollOver getAsset(int index) {
        String elementXPath = String.format("(%s%s)[%d]", listXPath, elementXPathTemplate, index);
        return new AssetWithRollOver(elementXPath, true);
    }
}
